home *** CD-ROM | disk | FTP | other *** search
- /*
- File: FocusLib.h
-
- Contains: Library routines for focusing (setting up for drawing into a facet)
-
- Owned by: Jens Alfke
-
- Copyright: © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
-
-
- THEORY OF OPERATION:
-
- FocusLib sets up the drawing environment for a QuickDraw-based part so that
- it can start drawing into a facet. It provides both a one-time change of
- focus (via the Focus call) and a way to set the focus but restore it later
- when the current scope exits (via the CFocus object.)
-
- Focus() and FocusWindow() are slightly different for offscreen facets. If the
- facet is in an offscreen canvas, Focus will set up to draw into that canvas;
- this is what one usually wants to do. On the other hand, FocusWindow will
- always focus onto an on-screen canvas, even for an off-screen facet. Use
- FocusWindow for things like rubber-banding where your drawing needs to show
- up immediately, even if the facet is offscreen.
-
- The CFocus object deserves an example:
-
- void DrawSomething( ODFacet *facet )
- {
- CFocus f(facet); // Creates a CFocus object on the stack, which
- // changes the focus but stores the old state
- ....drawing code...
- }
-
- Declaring the CFocus object calls its constructor, which sets the focus and
- stores the old state in the CFocus object itself (on the stack.) When its
- scope exists, the CFocus object's destructor is called, which restores the
- old focus.
-
- CFocus inherits from Destructo (see Except.h) so it will now be destructed
- properly if an exception is thrown while it's active. You no longer need to
- catch the exception and manually destruct the CFocus.
- */
-
-
- #ifndef _FOCUSLIB_
- #define _FOCUSLIB_
-
- #ifndef _EXCEPT_
- #include <Except.h>
- #endif
-
- #ifndef __QUICKDRAW__
- #include <QuickDraw.h>
- #endif
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
-
- #ifdef __cplusplus
- class ODCanvas;
- class ODShape;
- class ODFacet;
- struct Environment;
- #else
- #ifndef som_h
- #include <som.h>
- #endif
- #ifndef SOM_ODCanvas_h
- #include <Canvas.h>
- #endif
- #ifndef SOM_ODShape_h
- #include <Shape.h>
- #endif
- #ifndef SOM_ODFacet_h
- #include <Facet.h>
- #endif
- #endif
-
-
- /* FocusState stores the state data for QD focusing.
- C users should allocate one on the stack and call BeginFocus and
- EndFocus (q.v.) to do the focusing.
- C++ users should ignore FocusState and simply allocate a CFocus object
- (see below).
- */
-
- struct FocusState
- {
- GrafPtr fPort; // Port to restore after unfocusing
- Point fOrigin;
- RgnHandle fClip;
- ODBoolean fPrintingPostScript;
- GrafPtr fFocusPort; // Port we're focusing to
-
- #ifdef __cplusplus
- ODBoolean BeginFocus( Environment*, ODFacet*, ODBoolean toContent,
- ODBoolean toWindow, ODShape *clipTo );
- void EndFocus( );
- #endif
- };
- typedef struct FocusState FocusState;
-
-
- /* CFocus is a class for C++ users. Just allocate one as a local variable:
- the constructor will focus, and the destructor (called when it goes out
- of scope or an exception is thrown) will unfocus.
- CFocusWindow is just like CFocus, but focuses to the window instead of
- the facet's canvas (if they're different.)
- */
-
- #ifdef __cplusplus
- class CFocus :public Destructo {
- public:
- CFocus( Environment*, ODFacet* );
- CFocus( Environment*, ODFacet*, ODShape *clipTo );
- virtual ~CFocus();
-
- ODBoolean PrintingPostScript( ) {return f.fPrintingPostScript;}
-
- protected:
- FocusState f;
- };
- #define CFocusContent CFocus
-
- class CFocusFrame :public Destructo {
- public:
- CFocusFrame( Environment*, ODFacet* );
- CFocusFrame( Environment*, ODFacet*, ODShape *clipTo );
- virtual ~CFocusFrame();
-
- ODBoolean PrintingPostScript( ) {return f.fPrintingPostScript;}
-
- protected:
- FocusState f;
- };
-
- class CFocusWindow :public Destructo {
- public:
- CFocusWindow( Environment* ev, ODFacet* );
- CFocusWindow( Environment*, ODFacet*, ODShape *clipTo );
- virtual ~CFocusWindow();
-
- ODBoolean PrintingPostScript( ) {return f.fPrintingPostScript;}
-
- protected:
- FocusState f;
- };
- #define CFocusWindowContent CFocusWindow
-
- class CFocusWindowFrame :public Destructo {
- public:
- CFocusWindowFrame( Environment* ev, ODFacet* );
- CFocusWindowFrame( Environment*, ODFacet*, ODShape *clipTo );
- virtual ~CFocusWindowFrame();
-
- ODBoolean PrintingPostScript( ) {return f.fPrintingPostScript;}
-
- protected:
- FocusState f;
- };
-
- #endif
-
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- // For C only:
- void BeginFocus( Environment*, FocusState*, ODFacet*, ODBoolean toContent,
- ODBoolean toWindow, ODShape* clipTo );
- void EndFocus( FocusState* );
-
-
- // ODBeginPostScriptClip sets the PostScript clipping path to the given shape.
- // ODEndPostScriptClip resets PostScript clipping.
- // Neither has any effect except while printing to a PostScript printer.
- // If you are using FocusLib to do your clipping you don't need to call these.
- void ODBeginPostScriptClip( Environment* ev, ODShape* );
- void ODEndPostScriptClip( );
-
-
- // GetCanvasGeometryMode returns the proper geometry mode to use for shapes
- // being used on a given canvas. This is usually kODLoseGeometry, indicating
- // that regions can be used for greater efficiency, or kODPreserveGeometry
- // when printing to a PostScript printer or via any GX print job.
- // This function should be used to get the geometry mode to be used for
- // shapes related to clipping.
-
- ODGeometryMode GetCanvasGeometryMode( Environment *ev, ODCanvas *canvas );
-
- #ifdef __cplusplus
- }
- #endif
-
- #endif //_FOCUSLIB_
-